import { Component, OnInit } from "@angular/core";
import { CesiumMap } from "src/app/cesium-map/utils/cesiumMap";
import { InitCesiumService } from "src/app/cesium-map/services/InitCesiumService";
declare var Cesium;
@Component({
  selector: 'app-models-demo',
  templateUrl: './models-demo.component.html',
  styleUrls: ["./models-demo.component.less"],
})
export class ModelsDemoComponent implements OnInit {
  options: any = {
    infoBox: false,
    selectionIndicator: false,
    shadows: true,
    shouldAnimate: true,
  }


  list = [
    {
      id: 0,
      text: "Aircraft",
      url: 'assets/3dModels/Cesium_Air.glb',
      height: 5000.0,
    },
    {
      id: 1,
      text: "Drone",
      url: 'assets/3dModels/CesiumDrone.glb',
      height: 150.0,
    },
    {
      id: 2,
      text: "Ground Vehicle",
      url: 'assets/3dModels/GroundVehicle.glb',
      height: 0
    },
    {
      id: 3,
      text: "Hot Air Balloon",
      url: 'assets/3dModels/CesiumBalloon.glb',
      height: 1000.0
    },
    {
      id: 4,
      text: "Milk Truck",
      url: 'assets/3dModels/CesiumMilkTruck.glb',
      height: 0
    },
    {
      id: 5,
      text: "Skinned Character",
      url: 'assets/3dModels/Cesium_Man.glb',
      height: 0
    },
    {
      id: 6,
      text: "Unlit Box",
      url: 'assets/3dModels//BoxUnlit.gltf',
      height: 10.0
    },
    {
      id: 7,
      text: "Draco Compressed Model",
      url: 'assets/3dModels/CesiumMilkTruck.gltf',
      height: 0
    },
    // {
    //   text: "KTX2 Compressed Balloon",
    //   onselect: function () {
    //     if (!Cesium.FeatureDetection.supportsBasis(this.viewer.scene)) {
    //       window.alert(
    //         "This browser does not support Basis Universal compressed textures"
    //       );
    //     }
    //     this.createModel(
    //       "../SampleData/models/CesiumBalloonKTX2/CesiumBalloonKTX2.glb",
    //       1000.0
    //     );
    //   },
    // },
    {
      id: 8,
      text: "Instanced Box",
      url: 'assets/3dModels/BoxInstanced.gltf',
      height: 15
    },
  ];

  selectedValue: any = null
  cesiumMap: CesiumMap;
  Viewer: any;
  params;
  lanTianOSGB;
  constructor(private InitCesiumService: InitCesiumService) { }


  ngOnInit() {
    this.cesiumMap = new CesiumMap();
  }

  createModel(url, height) {
    this.Viewer.entities.removeAll();
    const position = Cesium.Cartesian3.fromDegrees(
      -123.0744619,
      44.0503706,
      height
    );
    const heading = Cesium.Math.toRadians(135);
    const pitch = 0;
    const roll = 0;
    const hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
    const orientation = Cesium.Transforms.headingPitchRollQuaternion(
      position,
      hpr
    );

    const entity = this.Viewer.entities.add({
      name: url,
      position: position,
      orientation: orientation,
      model: {
        uri: url,
        minimumPixelSize: 128,
        maximumScale: 20000,
      },
    });
    this.Viewer.trackedEntity = entity;
  }

  // 模型切换
  layerCut() {
    let par=this.list.filter(item=>item.id==this.selectedValue)
    this.createModel(par[0]['url'],par[0]['height'])
   }


  addlayer(img) {
    var layers = this.Viewer.scene.imageryLayers;

    layers.addImageryProvider(img);
  }
  mapCreate($event) {
    this.Viewer = $event;

    // this.gohome();
  }















}
